home *** CD-ROM | disk | FTP | other *** search
- //Change password routine
- //Michael J. Campbell, 1994
-
- #include <dos.h>
- #include <stdio.h>
- #include <graphics.h>
- #include <conio.h>
- #include <string.h>
- #include "keycodes.h"
-
- // Outside functions/variables
- extern char text[30], password[30];
- extern void write_text(int,int,int,int,int,int,int);
- extern int ESC_pressed;
- extern void wait(void);
-
-
- void change(void)
- {
-
- int tries = 0;
- FILE *fp;
-
- char temp_pass[30];
- strcpy(temp_pass,"");
- strcpy(text,"");
-
- // Prompt user to change password
- setfillstyle(SOLID_FILL,LIGHTGRAY);
- bar(203,203,437,287);
- setcolor(BLACK);
- settextstyle(SMALL_FONT,HORIZ_DIR,4);
- settextjustify(CENTER_TEXT,CENTER_TEXT);
- outtextxy(320,210,"Press <ESC> to cancel");
- settextjustify(RIGHT_TEXT,CENTER_TEXT);
-
- outtextxy(323,230," Enter OLD Password:");
- outtextxy(323,245," Enter NEW Password:");
- outtextxy(323,260,"Renter NEW Password:");
-
- // Get input loop
- while(1)
- {
- // Clear input lines
- bar(334,255,437,265);
- bar(334,240,437,250);
- bar(334,225,437,235);
-
- // Do some checking
- if(ESC_pressed) break;
- tries++;
-
- // Annoy user some more
- if(tries > 2) { wait(); break; }
-
- // Get password
- write_text(335,230,BLACK,BLACK,LIGHTGRAY,15,0);
-
- if(ESC_pressed) break;
-
- if(strcmp(text,password) == 0)
- {
- // Get new password
- write_text(335,245,BLACK,BLACK,LIGHTGRAY,15,0);
-
- if(ESC_pressed) break;
-
- // Put new password in temp variable
- strcpy(temp_pass,text);
-
- // Confirm new password loop
- do
- {
- // Get new password again
- write_text(335,260,BLACK,BLACK,LIGHTGRAY,15,0);
-
- if(ESC_pressed) break;
-
- // Confirm new password matches
- if(strcmp(text,temp_pass) == 0)
- {
- setcolor(BLACK);
- settextjustify(CENTER_TEXT,CENTER_TEXT);
- outtextxy(320,280,"Press <ENTER> To Accept");
-
- // Change the password
- if(getch() == ENTER)
- {
- fp = fopen("c:\\allow.use","w+");
- fprintf(fp,temp_pass);
- fclose(fp);
- ESC_pressed = 1;
- break;
- }
- else // Cancel change
- {
- ESC_pressed = 1;
- break;
- } // End if
-
- }
- else // Failure of new password confirmation
- {
- bar(334,255,437,265);
- setcolor(BLACK);
- outtextxy(335,260,"INCORRECT");
- delay(3000);
- bar(334,255,437,265);
- rewind(fp);
- } // End if
-
- } while(strcmp(text,temp_pass) != 0); // End do
-
- } // End if
-
- } // End while
-
- } // End function